SpotCheck Logo

Access Control

Java's access control allows the author of a class to guarantee correct usage of the fields and methods of that class. SpotCheck implements access control checking exactly as stipulated in the language specification. In the following example, "publicClass" defines four fields, each with different access. Method "aMethod" declares an instance of "publicClass", and then attempts to assign to each of the four fields.

access control screen shot

Since "aMethod" is declared within a subclass of "publicClass", access to "protectedField" is allowed. However, access to "privateField" is disallowed, since "aMethod" is not declared within "publicClass" itself. Similarly, since "aMethod" is outside of "externalPackage", default access is not allowed either.

© 1997 GenieWorks, LLC. All rights reserved